package com.yao.service.impl;

import com.yao.mapper.FinanceMapper;
import com.yao.mapper.UserMapper;
import com.yao.pojo.ManageFinances;
import com.yao.service.FinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 妖悲冥
 * @date 2021/5/23 0023   -    16:23
 */
@Service
public class FinanceServiceImpl implements FinanceService {
    @Autowired
    FinanceMapper financeMapper;

    @Override
    public List<String> selectFinances(ManageFinances finances) {
        List<String> strings = financeMapper.selectFinances(finances.getUserId(), finances.getFinancesId());
        //为2就用正则将多余的特殊字符删除并大写
        int id = 2;
        if (finances.getFinancesId() == id) {
            List<String> s = new ArrayList<>();
            for (String string : strings) {
                s.add(string.replaceAll("[()+.]", "").toUpperCase());
            }
            return s;
        }
        return strings;
    }

    @Override
    public String addFinances(ManageFinances finances) {
        finances.setId();
        if (financeMapper.addFinances(finances) != 0) {
            return "ok";
        }
        return "error";
    }

    @Override
    public String deleteFinances(ManageFinances finances) {
        if (financeMapper.deleteFinances(finances.getId()) != 0) {
            return "ok";
        }
        return "error";
    }
}
